package androidx.compose.ui.text.platform

import androidx.compose.ui.text.PlatformStringDelegate
import androidx.compose.ui.text.intl.PlatformLocale

// 最简单的本地实现（暂不使用 locale 做细粒度本地化处理
@Suppress("CAST_NEVER_SUCCEEDS")
internal class NativeStringDelegate : PlatformStringDelegate {

    override fun toUpperCase(string: String, locale: PlatformLocale): String {
        // TODO: 后续可接入 ohos.global.i18n 的大小写规则
        return string.uppercase()
    }

    override fun toLowerCase(string: String, locale: PlatformLocale): String {
        return string.lowercase()
    }

    override fun capitalize(string: String, locale: PlatformLocale): String {
        if (string.isEmpty()) return string
        // 使用 Unicode 友好的首字母 Titlecase
        return string.replaceFirstChar { ch ->
            if (ch.isLowerCase()) ch.titlecase() else ch.toString()
        }
    }

    override fun decapitalize(string: String, locale: PlatformLocale): String {
        if (string.isEmpty()) return string
        return string.replaceFirstChar { ch ->
            if (ch.isUpperCase()) ch.lowercase() else ch.toString()
        }
    }
}

// actual：返回 OHOS 的字符串委托实现
internal actual fun ActualStringDelegate(): PlatformStringDelegate = NativeStringDelegate()
